package com.huidz.calendar.daysfragment;

import android.Manifest;
import android.content.Context;
import android.graphics.Rect;
import android.os.Bundle;
import android.text.format.Time;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.TimePickerView;
import com.huidz.calendar.R;
import com.huidz.calendar.util.Apiutils;
import com.huidz.calendar.util.Util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import pub.devrel.easypermissions.EasyPermissions;

import static android.content.Context.INPUT_METHOD_SERVICE;

public class LowdayFragment extends Fragment implements View.OnClickListener {
    //用于获取视图
    private View root;

    private LinearLayout bwltime_line, bwltx_line, bwlbz_line;
    private TextView bwl_tiem,bwl_tixings;
    public static EditText edit,beizhu;
    /******************窗口里控件*******************/
    private RelativeLayout butixing, zhengdian, wufenzhong, shiwufen, sanshifen, yixiaoshi, yitian, santian, wutian;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        root = inflater.inflate(R.layout.fragment_addsr, container, false);//初始加载
        if (Apiutils.isNetworkConnecteds)
            InitView(root);
        return root;
    }

    private static PopupWindow popupWindow;

    /**
     * 初始加载视图
     */
    public void InitView(View view) {
        bwltime_line = view.findViewById(R.id.bwltime_line);
        bwltime_line.setOnClickListener(this);
        bwltx_line = view.findViewById(R.id.bwltx_line);
        bwlbz_line = view.findViewById(R.id.bwlbz_line);
        bwlbz_line.setOnClickListener(this);
        bwl_tixings=view.findViewById(R.id.bwl_tixings);
        bwl_tiem = view.findViewById(R.id.bwl_tiem);
        beizhu=view.findViewById(R.id.beizhu);
        edit = view.findViewById(R.id.edit);
        edit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                edit.setFocusable(true);
                edit.setFocusableInTouchMode(true);
                edit.requestFocus();
                if (!isSoftShowing()) {
                    getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                }
            }
        });
        DateTimePpicke(getActivity());
    }

    public void lost() {
        edit.setFocusable(false);
        edit.setFocusableInTouchMode(false);
        edit.requestFocus();
        if (isSoftShowing()) {
            final View v = getActivity().getWindow().peekDecorView();
            if (v != null && v.getWindowToken() != null) {
                InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
            }
        }
    }
    private ImageView butixing_check_yes, zhengdian_check_yes, wufenzhong_check_yes, shiwufen_check_yes, sanshifen_check_yes, yixiaoshi_check_yes, yitian_check_yes, santian_check_yes, wutian_check_yes;
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.bwltime_line:
                lost();
                pvTime.show();
                break;
            case R.id.bwltx_line:
                lost();
                window(getActivity());
                break;
            case R.id.bwlbz_line:
                lost();
                break;
        }
    }

    private String txtime;
    private boolean isSoftShowing() {
        //获取当屏幕内容的高度
        int screenHeight = getActivity().getWindow().getDecorView().getHeight();
        //获取View可见区域的bottom
        Rect rect = new Rect();
        //DecorView即为activity的顶级view
        getActivity().getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
        //考虑到虚拟导航栏的情况（虚拟导航栏情况下：screenHeight = rect.bottom + 虚拟导航栏高度）
        //选取screenHeight*2/3进行判断
        return screenHeight * 2 / 3 > rect.bottom;
    }
    private int  check_tixing_id = 1;
    public static int tixingid;
    public void window(Context context) {
        View popupwindowview = LayoutInflater.from(context).inflate(
                R.layout.activity_tqwindow, null);
        butixing = popupwindowview.findViewById(R.id.butixing);
        zhengdian = popupwindowview.findViewById(R.id.zhengdian);
        wufenzhong = popupwindowview.findViewById(R.id.wufenzhong);
        shiwufen = popupwindowview.findViewById(R.id.shiwufen);
        sanshifen = popupwindowview.findViewById(R.id.sanshifen);
        yixiaoshi = popupwindowview.findViewById(R.id.yixiaoshi);
        yitian = popupwindowview.findViewById(R.id.yitian);
        santian = popupwindowview.findViewById(R.id.santian);
        wutian = popupwindowview.findViewById(R.id.wutian);
        butixing_check_yes = popupwindowview.findViewById(R.id.butixing_check_yes);
        zhengdian_check_yes = popupwindowview.findViewById(R.id.zhengdian_check_yes);
        wufenzhong_check_yes = popupwindowview.findViewById(R.id.wufenzhong_check_yes);
        shiwufen_check_yes = popupwindowview.findViewById(R.id.shiwufen_check_yes);
        sanshifen_check_yes = popupwindowview.findViewById(R.id.sanshifen_check_yes);
        yixiaoshi_check_yes = popupwindowview.findViewById(R.id.yixiaoshi_check_yes);
        yitian_check_yes = popupwindowview.findViewById(R.id.yitian_check_yes);
        santian_check_yes = popupwindowview.findViewById(R.id.santian_check_yes);
        wutian_check_yes = popupwindowview.findViewById(R.id.wutian_check_yes);
        Check_ChongFu(check_tixing_id,1);
        butixing.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                check_tixing_id = 0;
                tixingid = 0;
                popupWindow.dismiss();
                bwl_tixings.setText("不提醒");
            }
        });
        zhengdian.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                tixingid = 1;
                check_tixing_id = 1;
                popupWindow.dismiss();
                bwl_tixings.setText("正点提醒");
            }
        });
        wufenzhong.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                tixingid = 2;
                check_tixing_id = 2;
                popupWindow.dismiss();
                bwl_tixings.setText("提前5分钟");
            }
        });
        shiwufen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                check_tixing_id = 3;
                tixingid = 3;
                popupWindow.dismiss();
                bwl_tixings.setText("提前15分钟");
            }
        });
        sanshifen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                tixingid = 4;
                check_tixing_id = 4;
                popupWindow.dismiss();
                bwl_tixings.setText("提前30分钟");
            }
        });
        yixiaoshi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                tixingid = 5;
                check_tixing_id = 5;
                popupWindow.dismiss();
                bwl_tixings.setText("提前一小时");
            }
        });
        yitian.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                tixingid = 6;
                check_tixing_id = 6;
                popupWindow.dismiss();
                bwl_tixings.setText("提前1天");
            }
        });
        santian.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                tixingid = 7;
                check_tixing_id = 7;
                popupWindow.dismiss();
                bwl_tixings.setText("提前3天");
            }
        });
        wutian.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                tixingid = 8;
                check_tixing_id = 8;
                popupWindow.dismiss();
                bwl_tixings.setText("提前5天");
            }
        });
        popupWindow = new PopupWindow(popupwindowview, ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, true);
        popupWindow.setAnimationStyle(R.style.popwin_anim_style);
        popupWindow.setTouchable(true);
        popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                // TODO Auto-generated method stub
                WindowManager.LayoutParams lp = getActivity().getWindow().getAttributes();
                lp.alpha = 1f;
                getActivity().getWindow().setAttributes(lp);
            }
        });
        popupWindow.setFocusable(true);
        popupWindow.setOutsideTouchable(true);
        WindowManager.LayoutParams lp = getActivity().getWindow().getAttributes();
        lp.alpha = 0.4f;
        getActivity().getWindow().setAttributes(lp);
        popupWindow.showAtLocation(bwltx_line, Gravity.BOTTOM, 0, 0);
    }

    TimePickerView pvTime;
    public static String datetime_s="";
    public void DateTimePpicke(Context context) {
        Calendar selectedDate = Calendar.getInstance();
        Time t = new Time();
        t.setToNow(); // 取得系统时间。
        int year = t.year;
        int month = t.month;
        int day = t.monthDay;
        int mWay = selectedDate.get(Calendar.DAY_OF_WEEK);
        String mway = null;
        mway = Apiutils.GetWeekday(mWay);
        bwl_tiem.setText(year + "年" + (month + 1) + "月" + day + "日" + " 周" + mway);
        datetime_s=date2TimeStamp(year + "年" + (month + 1) + "月" + day + "日");
        selectedDate.set(year, month, day);
        pvTime = new TimePickerBuilder(context, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(date);
                int year = calendar.get(Calendar.YEAR);
                int month = calendar.get(Calendar.MONTH) + 1;
                int day = calendar.get(Calendar.DAY_OF_MONTH);
                int mway = calendar.get(Calendar.DAY_OF_WEEK);
                int h = calendar.get(Calendar.HOUR_OF_DAY);
                bwl_tiem.setText(year + "年" + month + "月" + day + "日" + " 周" + Apiutils.GetWeekday(mway));
                datetime_s=date2TimeStamp(year + "年" + month + "月" + day + "日");
                if (month > 9 && day > 9)
                    txtime = year + "" + month + "" + day + "" + h + "" + calendar.get(Calendar.MINUTE) + "";
                else if (month <= 9 && day > 9)
                    txtime = year + "0" + month + "" + day + "" + h + "" + calendar.get(Calendar.MINUTE) + "";
                else if (month > 9 && day <= 9)
                    txtime = year + "" + month + "0" + day + "" + h + "" + calendar.get(Calendar.MINUTE) + "";
                else
                    txtime = year + "0" + month + "0" + day + "" + h + "" + calendar.get(Calendar.MINUTE) + "";
            }
        }).setDate(selectedDate)
                .setSubmitColor(R.color.text_msg)
                .setCancelColor(R.color.text_msg)
                .setOutSideCancelable(false)
                .setType(new boolean[]{true, true, true, false, false, false})
                .setLabel("年", "月", "日", "时", "分", "秒")
                .build();
    }
    public static long stringToLong(String strTime, String formatType)
            throws ParseException {
        Date date = stringToDate(strTime, formatType); // String类型转成date类型
        if (date == null) {
            return 0;
        } else {
            long currentTime = dateToLong(date); // date类型转成long类型
            return currentTime;
        }
    }
    public static long dateToLong(Date date) {
        return date.getTime();
    }

    public static Date stringToDate(String strTime, String formatType)
            throws ParseException {
        SimpleDateFormat formatter = new SimpleDateFormat(formatType);
        Date date = null;
        date = formatter.parse(strTime);
        return date;
    }


    private void requestStoreAndCameraPermission() {
        String[] permissions = {Manifest.permission.READ_CALENDAR, Manifest.permission.WRITE_CALENDAR};
        if (EasyPermissions.hasPermissions(getActivity(), permissions)) {
            //权限获取成功
            try {
                long currentTime = stringToLong("2019 - 12 - 30 15:30", "yyyy-MM-dd HH:mm"); // date类型转成long类型
                Util.addCalendarEvent(getActivity(), "tixing", "这是一个提醒", currentTime, 1,0);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        } else {
            //没有权限，调用方法申请权限
            EasyPermissions.requestPermissions(this, "程序运行需要日历权限", 1, permissions);
        }
    }


    public void Check_ChongFu(int post, int popupwindowid) {
        if (popupwindowid == 1)
            switch (post) {
                case 0:
                    butixing.setBackgroundResource(R.drawable.rela_tixing_check);
                    zhengdian.setBackgroundResource(R.drawable.rela_tixing);
                    wufenzhong.setBackgroundResource(R.drawable.rela_tixing);
                    shiwufen.setBackgroundResource(R.drawable.rela_tixing);
                    sanshifen.setBackgroundResource(R.drawable.rela_tixing);
                    yixiaoshi.setBackgroundResource(R.drawable.rela_tixing);
                    yitian.setBackgroundResource(R.drawable.rela_tixing);
                    santian.setBackgroundResource(R.drawable.rela_tixing);
                    wutian.setBackgroundResource(R.drawable.rela_tixing);
                    butixing_check_yes.setVisibility(View.VISIBLE);
                    zhengdian_check_yes.setVisibility(View.GONE);
                    wufenzhong_check_yes.setVisibility(View.GONE);
                    shiwufen_check_yes.setVisibility(View.GONE);
                    sanshifen_check_yes.setVisibility(View.GONE);
                    yixiaoshi_check_yes.setVisibility(View.GONE);
                    yitian_check_yes.setVisibility(View.GONE);
                    santian_check_yes.setVisibility(View.GONE);
                    wutian_check_yes.setVisibility(View.GONE);
                    break;
                case 1:
                    butixing.setBackgroundResource(R.drawable.rela_tixing);
                    zhengdian.setBackgroundResource(R.drawable.rela_tixing_check);
                    wufenzhong.setBackgroundResource(R.drawable.rela_tixing);
                    shiwufen.setBackgroundResource(R.drawable.rela_tixing);
                    sanshifen.setBackgroundResource(R.drawable.rela_tixing);
                    yixiaoshi.setBackgroundResource(R.drawable.rela_tixing);
                    yitian.setBackgroundResource(R.drawable.rela_tixing);
                    santian.setBackgroundResource(R.drawable.rela_tixing);
                    wutian.setBackgroundResource(R.drawable.rela_tixing);
                    butixing_check_yes.setVisibility(View.GONE);
                    zhengdian_check_yes.setVisibility(View.VISIBLE);
                    wufenzhong_check_yes.setVisibility(View.GONE);
                    shiwufen_check_yes.setVisibility(View.GONE);
                    sanshifen_check_yes.setVisibility(View.GONE);
                    yixiaoshi_check_yes.setVisibility(View.GONE);
                    yitian_check_yes.setVisibility(View.GONE);
                    santian_check_yes.setVisibility(View.GONE);
                    wutian_check_yes.setVisibility(View.GONE);
                    break;
                case 2:
                    butixing.setBackgroundResource(R.drawable.rela_tixing);
                    zhengdian.setBackgroundResource(R.drawable.rela_tixing);
                    wufenzhong.setBackgroundResource(R.drawable.rela_tixing_check);
                    shiwufen.setBackgroundResource(R.drawable.rela_tixing);
                    sanshifen.setBackgroundResource(R.drawable.rela_tixing);
                    yixiaoshi.setBackgroundResource(R.drawable.rela_tixing);
                    yitian.setBackgroundResource(R.drawable.rela_tixing);
                    santian.setBackgroundResource(R.drawable.rela_tixing);
                    wutian.setBackgroundResource(R.drawable.rela_tixing);
                    butixing_check_yes.setVisibility(View.GONE);
                    zhengdian_check_yes.setVisibility(View.GONE);
                    wufenzhong_check_yes.setVisibility(View.VISIBLE);
                    shiwufen_check_yes.setVisibility(View.GONE);
                    sanshifen_check_yes.setVisibility(View.GONE);
                    yixiaoshi_check_yes.setVisibility(View.GONE);
                    yitian_check_yes.setVisibility(View.GONE);
                    santian_check_yes.setVisibility(View.GONE);
                    wutian_check_yes.setVisibility(View.GONE);
                    break;
                case 3:
                    butixing.setBackgroundResource(R.drawable.rela_tixing);
                    zhengdian.setBackgroundResource(R.drawable.rela_tixing);
                    wufenzhong.setBackgroundResource(R.drawable.rela_tixing);
                    shiwufen.setBackgroundResource(R.drawable.rela_tixing_check);
                    sanshifen.setBackgroundResource(R.drawable.rela_tixing);
                    yixiaoshi.setBackgroundResource(R.drawable.rela_tixing);
                    yitian.setBackgroundResource(R.drawable.rela_tixing);
                    santian.setBackgroundResource(R.drawable.rela_tixing);
                    wutian.setBackgroundResource(R.drawable.rela_tixing);
                    butixing_check_yes.setVisibility(View.GONE);
                    zhengdian_check_yes.setVisibility(View.GONE);
                    wufenzhong_check_yes.setVisibility(View.GONE);
                    shiwufen_check_yes.setVisibility(View.VISIBLE);
                    sanshifen_check_yes.setVisibility(View.GONE);
                    yixiaoshi_check_yes.setVisibility(View.GONE);
                    yitian_check_yes.setVisibility(View.GONE);
                    santian_check_yes.setVisibility(View.GONE);
                    wutian_check_yes.setVisibility(View.GONE);
                    break;
                case 4:
                    butixing.setBackgroundResource(R.drawable.rela_tixing);
                    zhengdian.setBackgroundResource(R.drawable.rela_tixing);
                    wufenzhong.setBackgroundResource(R.drawable.rela_tixing);
                    shiwufen.setBackgroundResource(R.drawable.rela_tixing);
                    sanshifen.setBackgroundResource(R.drawable.rela_tixing_check);
                    yixiaoshi.setBackgroundResource(R.drawable.rela_tixing);
                    yitian.setBackgroundResource(R.drawable.rela_tixing);
                    santian.setBackgroundResource(R.drawable.rela_tixing);
                    wutian.setBackgroundResource(R.drawable.rela_tixing);
                    butixing_check_yes.setVisibility(View.GONE);
                    zhengdian_check_yes.setVisibility(View.GONE);
                    wufenzhong_check_yes.setVisibility(View.GONE);
                    shiwufen_check_yes.setVisibility(View.GONE);
                    sanshifen_check_yes.setVisibility(View.VISIBLE);
                    yixiaoshi_check_yes.setVisibility(View.GONE);
                    yitian_check_yes.setVisibility(View.GONE);
                    santian_check_yes.setVisibility(View.GONE);
                    wutian_check_yes.setVisibility(View.GONE);
                    break;
                case 5:
                    butixing.setBackgroundResource(R.drawable.rela_tixing);
                    zhengdian.setBackgroundResource(R.drawable.rela_tixing);
                    wufenzhong.setBackgroundResource(R.drawable.rela_tixing);
                    shiwufen.setBackgroundResource(R.drawable.rela_tixing);
                    sanshifen.setBackgroundResource(R.drawable.rela_tixing);
                    yixiaoshi.setBackgroundResource(R.drawable.rela_tixing_check);
                    yitian.setBackgroundResource(R.drawable.rela_tixing);
                    santian.setBackgroundResource(R.drawable.rela_tixing);
                    wutian.setBackgroundResource(R.drawable.rela_tixing);
                    butixing_check_yes.setVisibility(View.GONE);
                    zhengdian_check_yes.setVisibility(View.GONE);
                    wufenzhong_check_yes.setVisibility(View.GONE);
                    shiwufen_check_yes.setVisibility(View.GONE);
                    sanshifen_check_yes.setVisibility(View.GONE);
                    yixiaoshi_check_yes.setVisibility(View.VISIBLE);
                    yitian_check_yes.setVisibility(View.GONE);
                    santian_check_yes.setVisibility(View.GONE);
                    wutian_check_yes.setVisibility(View.GONE);
                    break;
                case 6:
                    butixing.setBackgroundResource(R.drawable.rela_tixing);
                    zhengdian.setBackgroundResource(R.drawable.rela_tixing);
                    wufenzhong.setBackgroundResource(R.drawable.rela_tixing);
                    shiwufen.setBackgroundResource(R.drawable.rela_tixing);
                    sanshifen.setBackgroundResource(R.drawable.rela_tixing);
                    yixiaoshi.setBackgroundResource(R.drawable.rela_tixing);
                    yitian.setBackgroundResource(R.drawable.rela_tixing_check);
                    santian.setBackgroundResource(R.drawable.rela_tixing);
                    wutian.setBackgroundResource(R.drawable.rela_tixing);
                    butixing_check_yes.setVisibility(View.GONE);
                    zhengdian_check_yes.setVisibility(View.GONE);
                    wufenzhong_check_yes.setVisibility(View.GONE);
                    shiwufen_check_yes.setVisibility(View.GONE);
                    sanshifen_check_yes.setVisibility(View.GONE);
                    yixiaoshi_check_yes.setVisibility(View.GONE);
                    yitian_check_yes.setVisibility(View.VISIBLE);
                    santian_check_yes.setVisibility(View.GONE);
                    wutian_check_yes.setVisibility(View.GONE);
                    break;
                case 7:
                    butixing.setBackgroundResource(R.drawable.rela_tixing);
                    zhengdian.setBackgroundResource(R.drawable.rela_tixing);
                    wufenzhong.setBackgroundResource(R.drawable.rela_tixing);
                    shiwufen.setBackgroundResource(R.drawable.rela_tixing);
                    sanshifen.setBackgroundResource(R.drawable.rela_tixing);
                    yixiaoshi.setBackgroundResource(R.drawable.rela_tixing);
                    yitian.setBackgroundResource(R.drawable.rela_tixing);
                    santian.setBackgroundResource(R.drawable.rela_tixing_check);
                    wutian.setBackgroundResource(R.drawable.rela_tixing);
                    butixing_check_yes.setVisibility(View.GONE);
                    zhengdian_check_yes.setVisibility(View.GONE);
                    wufenzhong_check_yes.setVisibility(View.GONE);
                    shiwufen_check_yes.setVisibility(View.GONE);
                    sanshifen_check_yes.setVisibility(View.GONE);
                    yixiaoshi_check_yes.setVisibility(View.GONE);
                    yitian_check_yes.setVisibility(View.GONE);
                    santian_check_yes.setVisibility(View.VISIBLE);
                    wutian_check_yes.setVisibility(View.GONE);
                    break;
                case 8:
                    butixing.setBackgroundResource(R.drawable.rela_tixing);
                    zhengdian.setBackgroundResource(R.drawable.rela_tixing);
                    wufenzhong.setBackgroundResource(R.drawable.rela_tixing);
                    shiwufen.setBackgroundResource(R.drawable.rela_tixing);
                    sanshifen.setBackgroundResource(R.drawable.rela_tixing);
                    yixiaoshi.setBackgroundResource(R.drawable.rela_tixing);
                    yitian.setBackgroundResource(R.drawable.rela_tixing);
                    santian.setBackgroundResource(R.drawable.rela_tixing);
                    wutian.setBackgroundResource(R.drawable.rela_tixing_check);
                    butixing_check_yes.setVisibility(View.GONE);
                    zhengdian_check_yes.setVisibility(View.GONE);
                    wufenzhong_check_yes.setVisibility(View.GONE);
                    shiwufen_check_yes.setVisibility(View.GONE);
                    sanshifen_check_yes.setVisibility(View.GONE);
                    yixiaoshi_check_yes.setVisibility(View.GONE);
                    yitian_check_yes.setVisibility(View.GONE);
                    santian_check_yes.setVisibility(View.GONE);
                    wutian_check_yes.setVisibility(View.VISIBLE);
                    break;
            }
    }

    public static String date2TimeStamp(String date) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
            return String.valueOf(sdf.parse(date).getTime() / 1000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
}